
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>去除字符串左右的空格</title>
    <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" media="all"/>
    <link rel="stylesheet" type="text/css" href="../../css/bootstrap-theme.min.css" media="all"/>
    <link rel="stylesheet" type="text/css" href="../../css/reset.css" media="all"/>
</head>
<body>
<div class="demo1 tc">
    <input class="input" type="text" value="[     需要过滤的空格      ]" name="" id="input"/>
    <button class="btn btn-primary" id="btn">过滤</button>
</div>
<script>
    (function(){
        var input = document.getElementById('input');
        var btn = document.getElementById('btn');
        btn.onclick = function(){
            input.value = input.value.replace(/(\s|\u00A0)+|(\s|\u00A0)+/g,'');
        }
    }());
</script>
</body>
</html>